﻿/*==========================================================
	TASK 6:                            {Console InputOutput}
	Write a program that reads the coefficients a, b and c 
    of a quadratic equation ax2+bx+c=0 
    and solves it (prints its real roots).   
==========================================================*/

using System;
using System.Collections.Generic;

class QuadricEquation
{
    static void Main()
    {
        Console.WriteLine("quadric equation ax2+bx+c=0");

        Console.Write("Enter a=");
        int a = int.Parse(Console.ReadLine());

        Console.Write("Enter b=");
        int b = int.Parse(Console.ReadLine());

        Console.Write("Enter c=");
        int c = int.Parse(Console.ReadLine());

        float D = (b * b) - 4 * a * c;
        float x, x1, x2;
        
        if (a == 0)
        {
            Console.WriteLine("This isn't a quadratic equation, \"a\" can't be 0.");
        }

        else
        {
            if (D < 0)
            {
                Console.WriteLine("The equation hasn't real roots");
            }

            if (D == 0)
            {
                x = -b / (2 * a);
                Console.WriteLine("The equation has one real root x={0}", x);
            }

            if (D > 0)
            {
                x1 = (-b - (float)Math.Sqrt(D)) / (2 * a);
                x2 = (-b + (float)Math.Sqrt(D)) / (2 * a);
                Console.WriteLine("The equation has two real roots:\nx1={0}  and  x2={1}", x1, x2);
            }
        }
    }
}

